package org.redmagic.client.location;

import java.io.File;
import java.net.URI;

import org.redmagic.client.api.Location;
import org.redmagic.client.api.LocationFactory;
import org.w3c.dom.Element;

public class FileLocationFactory implements LocationFactory {
	
	@Override
	public Location createLocation(Element location) {
		
		// Get the cache name
		String name = location.getAttribute("name"); // optional
		
		// Get the cache uri
		URI uri = null;
		try {
			String filePath = location.getAttribute("file"); // required
			uri = new File(filePath).toURI();

		} catch (Exception e) {

			throw new RuntimeException("Unable to access file at location: " + uri);
		}
		
		return new FileLocation(name, uri);
	}

}
